/**
 * 
 */
let hr = new Vue({
	el:'#hrRegister2',
	data:{
		percentage:0,
		imageUrl:'',
		selected:sessionStorage.getItem("bname"),
		selectedBid:sessionStorage.getItem("bid"),
		
		divActive:[
			{div:true,index:0},
			{div:false,index:1},
			{div:false,index:2}
		],
		bussList:[],
		batchList:[],
		selectedBatchList:[],
		hr:{
			bid:'',
			batchid:'',
			hjobname:'',
			hid:'',
			hpwd:'',
			hpwd2:'',
			hgender:'',
			hphone:'',
			himg:null,
			hemail:'',
			bname:'',
			batchname:''
			
		}
	},
	methods:{
		uploadUserImg(item){
			//console.log(item);
			this.imageUrl = URL.createObjectURL(item.file);//blobUrl
			console.log(this.imageUrl);
			this.hr.himg = item.file;
		},
		add(){
			let data = new FormData();
			data.append("hid",this.hr.hid);
			data.append("hpwd",this.hr.hpwd);
			data.append("bid",this.selectedBid);
			data.append("hjobname",this.selected);
			data.append("batchid",this.hr.batchid);
			data.append("hgender",this.hr.hgender);
			data.append("hemail",this.hr.hemail);
			data.append("hphone",this.hr.hphone);	
			data.append("himg",this.hr.himg);
			axios.post('/hrt/add',data).then(resp=>{
				this.$message("注册成功，请登录");
				this.percentage = 100;
				setTimeout(()=>{
						window.location.href='http://localhost:8082/';
					},3000);
			}).catch();
		},
		changeBatchid(index){
			
		},
		changeBid(index){
			this.selectedBid = this.bussList[index].bid;
			this.selectedBatchList = [];
			this.getBatch();
	//		console.log(event+"-");
		},
		nextBtn(index){
			if(index<2){
				this.divActive[index].div = false;
				this.divActive[index+1].div = true;
				this.percentage+=100/2;
			}
		},
		backBtn(index){
			if(index>0){
				this.divActive[index].div = false;
				this.divActive[index-1].div = true;
				this.percentage-=100/2;
			}
		},
		process(p){
			return p===100?'已完成':'未完成';
		},
		getBname(){
			axios.post('/manager/getbname').then(resp=>{
				if(resp!==null){
					this.bussList = resp.data;
					
				}
			}).catch();
		},
		getBatch(){
			// /manager/getbatch
			axios.post('/manager/getbatch').then(resp=>{
				if(resp!==null){
					this.batchList = resp.data;
					for(i in this.batchList){
						if(this.batchList[i].bname===this.selected){
							this.selectedBatchList.push(this.batchList[i]);
						}
					}
				}
			}).catch();
		}
	},
	created(){
		this.getBname();
		this.getBatch();
	}
});